package com.syh.jn.scm.infrastructure.repository.impl.upstream.base;

import cn.redscarf.commons.wrapper.Wrapper;
import com.syh.core.ddd.infrastructure.repository.AbstractAggregateRepository;
import com.syh.jn.scm.domain.upstream.entity.base.UpNewGoodsRequest;
import com.syh.jn.scm.domain.upstream.repository.base.UpNewGoodsRequestRepository;
import com.syh.jn.scm.dto.upstream.base.UpNewGoodsRequestVo;
import com.syh.jn.scm.infrastructure.repository.model.base.goods.NewGoodsRequestModel;
import com.syh.jn.scm.infrastructure.repository.utils.SQLAliasGenerateUtil;
import com.syh.jn.scm.infrastructure.wrapper.BaseResolve;
import com.syh.jn.scm.infrastructure.wrapper.ResolveToSQL;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Repository;

import java.util.HashMap;

/**
 * 商品申请管理
 */
@Repository
public class UpNewGoodsRequestRepositoryImpl extends AbstractAggregateRepository<UpNewGoodsRequest, NewGoodsRequestModel, Long> implements UpNewGoodsRequestRepository {
  @Override
  protected SQL getViewSql() {
    return new SQL(){{
      SELECT(
              SQLAliasGenerateUtil.aliasGenerate(NewGoodsRequestModel.class, "request", null)
      );
      FROM("T_BASE_UPSTREAM_NEW_GOODS_REQUEST request");
    }};
  }

  @Override
  protected Class getViewObject() {
    return UpNewGoodsRequestVo.class;
  }

  @Override
  protected BaseResolve getViewWrapperResolve(Wrapper wrapper) {
    HashMap<String, String> map = new HashMap();
    map.put("id", "request.ID");
    map.put("goodsName", "request.GOODS_NAME");
    map.put("auditStatus", "request.AUDIT_STATUS");
    map.put("businessEntityId", "request.BUSINESS_ENTITY_ID");
    map.put("createTimeStamp", "request.CREATE_TIME_STAMP");
    map.put("supId", "request.SUP_ID");
    ResolveToSQL parse = new ResolveToSQL(wrapper, (propertyName) -> {
      return map.get(propertyName);
    });
    return parse;
  }
}
